//
// Created by Tony on 2024/7/2.
//

#include "AccessFlags.h"
#include "../../../common/KeyWords.h"
#include "../../../compiler/Visitor.h"

namespace Parser {

RtCode::AccessFlag AccessFlags::getFlags() {
    RtCode::AccessFlag flags;
    for (auto child : children) {
        auto flagName = static_pointer_cast<Name>(child)->name();
        if (flagName == KeyWords::PUBLIC) {
            flags.addFlag(RtCode::AccessFlag::PUBLIC);
        } else if (flagName == KeyWords::PROTECT) {
            flags.addFlag(RtCode::AccessFlag::PROTECTED);
        } else if (flagName == KeyWords::PRIVATE) {
            flags.addFlag(RtCode::AccessFlag::PRIVATE);
        } else if (flagName == KeyWords::STATIC) {
            flags.addFlag(RtCode::AccessFlag::STATIC);
        } else if (flagName == KeyWords::NATIVE) {
            flags.addFlag(RtCode::AccessFlag::NATIVE);
        }
    }
    return flags;
}

int32_t AccessFlags::accept(Compiler::Visitor* visitor) { return visitor->visit(this); }

} // namespace Parser
